<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.11.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>cppMISC: include/designM/flyweight.hpp 源文件</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../cookie.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript" src="../../darkmode_toggle.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">cppMISC<span id="projectnumber">&#160;v1.1</span>
   </div>
   <div id="projectbrief">cppMisc 文档系统</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.11.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(1); });
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('../../',true,false,'search.php','搜索',false);
  $(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">载入中...</div>
<div class="SRStatus" id="Searching">搜索中...</div>
<div class="SRStatus" id="NoMatches">未找到</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="../../dir_7815f4a69fa470e020068bb120d080ef.html">designM</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="headertitle"><div class="title">flyweight.hpp</div></div>
</div><!--header-->
<div class="contents">
<a href="../../d5/d66/flyweight_8hpp.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span> </div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno">    9</span><span class="preprocessor">#pragma once</span></div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno">   10</span> </div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span><span class="preprocessor">#include &lt;mutex&gt;</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span><span class="preprocessor">#include &lt;map&gt;</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span> </div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno">   14</span><span class="preprocessor">#if !defined( FLYWEIGHT_USE_VARIANT )</span></div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"><a class="line" href="../../d5/d66/flyweight_8hpp.html#a7766293954bda6e102f9e7bbf1150bc4">   15</a></span><span class="preprocessor">#    define FLYWEIGHT_USE_VARIANT   (1)</span></div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno">   16</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno">   17</span> </div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno">   18</span><span class="preprocessor">#if FLYWEIGHT_USE_VARIANT == 1</span></div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno">   19</span><span class="preprocessor">#   include &quot;<a class="code" href="../../d9/d7a/variant_8hpp.html">container/variant.hpp</a>&quot;</span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno">   20</span><span class="preprocessor">#else</span></div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno">   21</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../d4/da4/namespaceprivate____.html">private__</a></div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno">   22</span>{</div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno">   23</span><span class="keyword">struct </span>dataItfc__{</div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno">   24</span>    <span class="keyword">virtual</span> ~dataItfc__(){}</div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno">   25</span>};</div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno">   26</span>}</div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno">   27</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno">   28</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../df/d8d/namespacewheels.html">wheels</a>{<span class="keyword">namespace </span>dm {</div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno">   29</span><span class="preprocessor">#if !FLYWEIGHT_USE_VARIANT</span></div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno">   30</span><span class="keyword">template</span>&lt; <span class="keyword">typename</span> dataType &gt;</div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno">   31</span><span class="keyword">struct </span>dataItfc : <span class="keyword">public</span> private__::dataItfc__</div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span>{</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span>    <span class="keyword">virtual</span> <span class="keywordtype">void</span> set( <span class="keyword">const</span> dataType&amp; d ) = 0;</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno">   34</span>    <span class="keyword">virtual</span> <span class="keyword">const</span> dataType&amp; get() <span class="keyword">const</span> = 0;</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span>};</div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno">   36</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno">   37</span><span class="keyword">template</span>&lt; <span class="keyword">typename</span> <span class="keywordtype">id</span>Type &gt;</div>
<div class="foldopen" id="foldopen00038" data-start="{" data-end="};">
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html">   38</a></span><span class="keyword">class </span><a class="code hl_class" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html">flyweight</a></div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span>{</div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span><span class="keyword">protected</span>:</div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span>    <span class="comment">// 考虑一个数据可能会被很多接口使用，这样需要考虑数据的线程安全</span></div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a7dc77d06397345dc870c14a12cddd09a">   42</a></span>    <span class="keyword">mutable</span> std::mutex                      <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a7dc77d06397345dc870c14a12cddd09a">m_mutex__</a>;</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span><span class="preprocessor">#if FLYWEIGHT_USE_VARIANT == 1</span></div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">   44</a></span>    std::map&lt; idType , wheels::variant &gt;    <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>;</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span><span class="preprocessor">#else</span></div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span>    std::map&lt; idType , private__::dataItfc__ * &gt;       <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>;</div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno">   48</span><span class="keyword">public</span>:</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno">   49</span><span class="preprocessor">#if FLYWEIGHT_USE_VARIANT == 1</span></div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aabbb5d899c06d79bb6313ff3dd02e5bc">   50</a></span>    <span class="keyword">using </span><a class="code hl_typedef" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aabbb5d899c06d79bb6313ff3dd02e5bc">iterator</a> = <span class="keyword">typename</span> std::map&lt; idType , wheels::variant &gt;::iterator;</div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno">   51</span><span class="preprocessor">#else</span></div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno">   52</span>    <span class="keyword">using </span><a class="code hl_typedef" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aabbb5d899c06d79bb6313ff3dd02e5bc">iterator</a> = <span class="keyword">typename</span> std::map&lt; idType , private__::dataItfc__ * &gt;::iterator;</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno">   53</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno">   54</span><span class="keyword">public</span>:</div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a49d29a3cd73d26b049d0b4ac62c6dccb">   55</a></span>    <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a49d29a3cd73d26b049d0b4ac62c6dccb">flyweight</a>(){}</div>
<div class="foldopen" id="foldopen00056" data-start="{" data-end="}">
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a54ec2b8348e9b7604c4f95d20c56cf16">   56</a></span>    <span class="keyword">virtual</span> <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a54ec2b8348e9b7604c4f95d20c56cf16">~flyweight</a>(){</div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span><span class="preprocessor">#if !FLYWEIGHT_USE_VARIANT</span></div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno">   58</span>        <span class="keywordflow">for</span>( <span class="keyword">auto</span> item : <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a> ){</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno">   59</span>            <span class="keyword">delete</span> item.second;</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno">   60</span>        }</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno">   61</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span>    }</div>
</div>
<div class="foldopen" id="foldopen00066" data-start="{" data-end="}">
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a17fcf615f125a91ad49f28a8b92eb208">   66</a></span>    <span class="keywordtype">bool</span> <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a17fcf615f125a91ad49f28a8b92eb208">has</a>( <span class="keyword">const</span> idType&amp; <span class="keywordtype">id</span> ){</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno">   67</span>        std::lock_guard&lt; std::mutex&gt; lock( <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a7dc77d06397345dc870c14a12cddd09a">m_mutex__</a> );</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno">   68</span>        <span class="keyword">auto</span> it = <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.find( <span class="keywordtype">id</span> );</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno">   69</span>        <span class="keywordflow">return</span> (it != <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.end() );</div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno">   70</span>    }</div>
</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span><span class="preprocessor">#if FLYWEIGHT_USE_VARIANT == 0</span></div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>    <span class="keyword">template</span>&lt; <span class="keyword">typename</span> T , <span class="keyword">typename</span> ...PARAMS &gt;</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span>    <span class="keywordtype">bool</span> <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aecc25a056ac2858e7ee8571e19c95245">set</a>( <span class="keyword">const</span> idType&amp; <span class="keywordtype">id</span> , PARAMS&amp;&amp;... args ){</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span>        <span class="keywordtype">bool</span> ret = <span class="keyword">true</span>;</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span> </div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span>        <span class="keyword">static_assert</span>( std::is_base_of&lt; private__ :: dataItfc__ , T&gt;::value , <span class="stringliteral">&quot;&quot;</span> );</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span>        <span class="keyword">static_assert</span>( ( std::is_class&lt; T &gt;::value &amp;&amp; std::is_default_constructible&lt; T &gt;::value ) || std::is_arithmetic&lt;T&gt;::value , <span class="stringliteral">&quot;&quot;</span> );</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno">   82</span>        <span class="keyword">auto</span> it = <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.find( <span class="keywordtype">id</span> );</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno">   83</span>        <span class="keywordflow">if</span>( it != <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.end() ){</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno">   84</span>            <span class="keyword">auto</span> p = <span class="keyword">dynamic_cast&lt;</span> dataItfc&lt;PARAMS...<span class="keyword">&gt;</span> * &gt;( it-&gt;second );</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span>            p-&gt;set( std::forward&lt;PARAMS&gt;(args)... );</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span>        }<span class="keywordflow">else</span>{</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span>            <span class="keywordflow">try</span>{</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno">   88</span>                <span class="keyword">auto</span> * t = <span class="keyword">new</span> T;</div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno">   89</span>                <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.insert( std::make_pair( <span class="keywordtype">id</span> , t ) );</div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno">   90</span>                t-&gt;set( std::forward&lt;PARAMS&gt;(args)... );</div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno">   91</span>            }<span class="keywordflow">catch</span>( std::bad_alloc&amp; ){</div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno">   92</span>                ret = <span class="keyword">false</span>;</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno">   93</span>            }</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno">   94</span>        }</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno">   95</span> </div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno">   96</span>        <span class="keywordflow">return</span> ret;</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno">   97</span>    }</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno">   98</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno">  102</span><span class="preprocessor">#if FLYWEIGHT_USE_VARIANT == 1</span></div>
<div class="foldopen" id="foldopen00103" data-start="{" data-end="}">
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#afa4a8a1bb26896762077219548c45cb1">  103</a></span>    <a class="code hl_class" href="../../dd/d54/classwheels_1_1variant.html">variant</a> <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#afa4a8a1bb26896762077219548c45cb1">get</a>( <span class="keyword">const</span> idType&amp; name ){</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno">  104</span> </div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno">  105</span>        std::lock_guard&lt; std::mutex&gt; lock( <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a7dc77d06397345dc870c14a12cddd09a">m_mutex__</a> );</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno">  106</span> </div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span>        <span class="keyword">auto</span> it = <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.find( name );</div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno">  108</span>        <span class="keywordflow">if</span>( it != <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.end() ){</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno">  109</span>            <span class="keywordflow">return</span> it-&gt;second;</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno">  110</span>        }</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno">  111</span> </div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno">  112</span>        <span class="keywordflow">return</span> {};</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno">  113</span>    }</div>
</div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno">  114</span> </div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno">  115</span>    <span class="keyword">template</span>&lt; <span class="keyword">typename</span> T &gt;</div>
<div class="foldopen" id="foldopen00116" data-start="{" data-end="}">
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aecc25a056ac2858e7ee8571e19c95245">  116</a></span>    <span class="keywordtype">void</span> <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aecc25a056ac2858e7ee8571e19c95245">set</a>( <span class="keyword">const</span> idType&amp; <span class="keywordtype">id</span> , <span class="keyword">const</span> T&amp; data ){</div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno">  117</span>        <span class="keyword">auto</span> var = <a class="code hl_function" href="../../dd/d54/classwheels_1_1variant.html#aec8c6372866cf7fd422a96e1164aa5c3">wheels::variant::make</a>( data );</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno">  118</span> </div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno">  119</span>        std::lock_guard&lt; std::mutex&gt; lock( <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a7dc77d06397345dc870c14a12cddd09a">m_mutex__</a> );</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno">  120</span> </div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno">  121</span>        <span class="keyword">auto</span> it = <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.find( <span class="keywordtype">id</span> );</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno">  122</span>        <span class="keywordflow">if</span>( it != <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.end() ){</div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno">  123</span>            it-&gt;second = std::move( var );</div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno">  124</span>        }<span class="keywordflow">else</span>{</div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno">  125</span>            <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.insert( std::make_pair( <span class="keywordtype">id</span> , var ) );</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno">  126</span>        }</div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno">  127</span>    }</div>
</div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno">  128</span> </div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno">  129</span>    <a class="code hl_class" href="../../dd/d54/classwheels_1_1variant.html">wheels::variant</a></div>
<div class="foldopen" id="foldopen00130" data-start="{" data-end="}">
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a4b18d2f2c9239ef249847effa4c34654">  130</a></span>    <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a4b18d2f2c9239ef249847effa4c34654">operator[]</a>(<span class="keyword">const</span> idType&amp; name){</div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno">  131</span>        <span class="keyword">auto</span> it = <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.find( name );</div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno">  132</span>        <span class="keywordflow">if</span>( it != <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.end() ){</div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno">  133</span>            <span class="keywordflow">return</span> it-&gt;second;</div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno">  134</span>        }</div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno">  135</span> </div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno">  136</span>        <span class="keywordflow">return</span> {};</div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno">  137</span>    }</div>
</div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno">  138</span><span class="preprocessor">#else</span></div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno">  139</span>    <span class="keyword">template</span>&lt; <span class="keyword">typename</span> T &gt;</div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno">  140</span>    T * <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#afa4a8a1bb26896762077219548c45cb1">get</a>( <span class="keyword">const</span> idType&amp; name ){</div>
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno">  141</span>        <span class="keyword">static_assert</span>( std::is_base_of&lt; private__ :: dataItfc__ , T &gt;::value , <span class="stringliteral">&quot;&quot;</span> );</div>
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno">  142</span>        std::lock_guard&lt; std::mutex&gt; lock( <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a7dc77d06397345dc870c14a12cddd09a">m_mutex__</a> );</div>
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno">  143</span> </div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno">  144</span>        <span class="keyword">auto</span> it = <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.find( name );</div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno">  145</span>        <span class="keywordflow">if</span>( it != <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.end() ){</div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno">  146</span>            <span class="keywordflow">return</span> <span class="keyword">dynamic_cast&lt;</span>T*<span class="keyword">&gt;</span>(it-&gt;second);</div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno">  147</span>        }</div>
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno">  148</span> </div>
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno">  149</span>        <span class="keywordflow">return</span> <span class="keyword">nullptr</span>;</div>
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno">  150</span>    }</div>
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno">  151</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a9823a13b2a62fe2f3d51724fb511fcc5">  152</a></span>    <span class="keywordtype">size_t</span> <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a9823a13b2a62fe2f3d51724fb511fcc5">count</a>(){ <span class="keywordflow">return</span> <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.size(); }</div>
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno">  153</span> </div>
<div class="line"><a id="l00154" name="l00154"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a21d8646f93f2c05086516d624a64a6ed">  154</a></span>    <span class="keywordtype">void</span> <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a21d8646f93f2c05086516d624a64a6ed">erase</a>( <a class="code hl_typedef" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aabbb5d899c06d79bb6313ff3dd02e5bc">iterator</a> it ){ <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.erase( it ); }</div>
<div class="line"><a id="l00155" name="l00155"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a9be751b89eaaec26423522f8940fae5a">  155</a></span>    <span class="keywordtype">void</span> <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a9be751b89eaaec26423522f8940fae5a">erase</a>( <a class="code hl_typedef" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aabbb5d899c06d79bb6313ff3dd02e5bc">iterator</a> b , <a class="code hl_typedef" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aabbb5d899c06d79bb6313ff3dd02e5bc">iterator</a> e ){ <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.erase( b , e ); }</div>
<div class="foldopen" id="foldopen00156" data-start="{" data-end="}">
<div class="line"><a id="l00156" name="l00156"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a93fe435fe2a7985d13bd392d17b55f7e">  156</a></span>    <span class="keywordtype">void</span> <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a93fe435fe2a7985d13bd392d17b55f7e">erase</a>( <span class="keyword">const</span> idType&amp; name ){</div>
<div class="line"><a id="l00157" name="l00157"></a><span class="lineno">  157</span>        <span class="keyword">auto</span> it = <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.find( name );</div>
<div class="line"><a id="l00158" name="l00158"></a><span class="lineno">  158</span>        <span class="keywordflow">if</span>( it != <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.end() ){</div>
<div class="line"><a id="l00159" name="l00159"></a><span class="lineno">  159</span>            <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.erase( it );</div>
<div class="line"><a id="l00160" name="l00160"></a><span class="lineno">  160</span>        }</div>
<div class="line"><a id="l00161" name="l00161"></a><span class="lineno">  161</span>    }</div>
</div>
<div class="line"><a id="l00162" name="l00162"></a><span class="lineno">  162</span> </div>
<div class="line"><a id="l00163" name="l00163"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#ad13fc697f56f6d01ea0efe645abd72f5">  163</a></span>    <a class="code hl_typedef" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aabbb5d899c06d79bb6313ff3dd02e5bc">iterator</a> <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#ad13fc697f56f6d01ea0efe645abd72f5">begin</a>(){ <span class="keywordflow">return</span> <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.begin(); }</div>
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno"><a class="line" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a233eb9be1af2526e82bfb0ead2191117">  164</a></span>    <a class="code hl_typedef" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aabbb5d899c06d79bb6313ff3dd02e5bc">iterator</a> <a class="code hl_function" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a233eb9be1af2526e82bfb0ead2191117">end</a>(){ <span class="keywordflow">return</span> <a class="code hl_variable" href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">m_itfcs__</a>.end(); }</div>
<div class="line"><a id="l00165" name="l00165"></a><span class="lineno">  165</span>};</div>
</div>
<div class="line"><a id="l00166" name="l00166"></a><span class="lineno">  166</span>}}</div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html">wheels::dm::flyweight</a></div><div class="ttdef"><b>定义</b> <a href="#l00038">flyweight.hpp:39</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_a10a14eefbe16b3a7c490b896a6c47da7"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a10a14eefbe16b3a7c490b896a6c47da7">wheels::dm::flyweight::m_itfcs__</a></div><div class="ttdeci">std::map&lt; idType, wheels::variant &gt; m_itfcs__</div><div class="ttdef"><b>定义</b> <a href="#l00044">flyweight.hpp:44</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_a17fcf615f125a91ad49f28a8b92eb208"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a17fcf615f125a91ad49f28a8b92eb208">wheels::dm::flyweight::has</a></div><div class="ttdeci">bool has(const idType &amp;id)</div><div class="ttdoc">判断是否存在指定的享元</div><div class="ttdef"><b>定义</b> <a href="#l00066">flyweight.hpp:66</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_a21d8646f93f2c05086516d624a64a6ed"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a21d8646f93f2c05086516d624a64a6ed">wheels::dm::flyweight::erase</a></div><div class="ttdeci">void erase(iterator it)</div><div class="ttdef"><b>定义</b> <a href="#l00154">flyweight.hpp:154</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_a233eb9be1af2526e82bfb0ead2191117"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a233eb9be1af2526e82bfb0ead2191117">wheels::dm::flyweight::end</a></div><div class="ttdeci">iterator end()</div><div class="ttdef"><b>定义</b> <a href="#l00164">flyweight.hpp:164</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_a49d29a3cd73d26b049d0b4ac62c6dccb"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a49d29a3cd73d26b049d0b4ac62c6dccb">wheels::dm::flyweight::flyweight</a></div><div class="ttdeci">flyweight()</div><div class="ttdef"><b>定义</b> <a href="#l00055">flyweight.hpp:55</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_a4b18d2f2c9239ef249847effa4c34654"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a4b18d2f2c9239ef249847effa4c34654">wheels::dm::flyweight::operator[]</a></div><div class="ttdeci">wheels::variant operator[](const idType &amp;name)</div><div class="ttdef"><b>定义</b> <a href="#l00130">flyweight.hpp:130</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_a54ec2b8348e9b7604c4f95d20c56cf16"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a54ec2b8348e9b7604c4f95d20c56cf16">wheels::dm::flyweight::~flyweight</a></div><div class="ttdeci">virtual ~flyweight()</div><div class="ttdef"><b>定义</b> <a href="#l00056">flyweight.hpp:56</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_a7dc77d06397345dc870c14a12cddd09a"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a7dc77d06397345dc870c14a12cddd09a">wheels::dm::flyweight::m_mutex__</a></div><div class="ttdeci">std::mutex m_mutex__</div><div class="ttdef"><b>定义</b> <a href="#l00042">flyweight.hpp:42</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_a93fe435fe2a7985d13bd392d17b55f7e"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a93fe435fe2a7985d13bd392d17b55f7e">wheels::dm::flyweight::erase</a></div><div class="ttdeci">void erase(const idType &amp;name)</div><div class="ttdef"><b>定义</b> <a href="#l00156">flyweight.hpp:156</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_a9823a13b2a62fe2f3d51724fb511fcc5"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a9823a13b2a62fe2f3d51724fb511fcc5">wheels::dm::flyweight::count</a></div><div class="ttdeci">size_t count()</div><div class="ttdef"><b>定义</b> <a href="#l00152">flyweight.hpp:152</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_a9be751b89eaaec26423522f8940fae5a"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#a9be751b89eaaec26423522f8940fae5a">wheels::dm::flyweight::erase</a></div><div class="ttdeci">void erase(iterator b, iterator e)</div><div class="ttdef"><b>定义</b> <a href="#l00155">flyweight.hpp:155</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_aabbb5d899c06d79bb6313ff3dd02e5bc"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aabbb5d899c06d79bb6313ff3dd02e5bc">wheels::dm::flyweight::iterator</a></div><div class="ttdeci">typename std::map&lt; idType, wheels::variant &gt;::iterator iterator</div><div class="ttdef"><b>定义</b> <a href="#l00050">flyweight.hpp:50</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_ad13fc697f56f6d01ea0efe645abd72f5"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#ad13fc697f56f6d01ea0efe645abd72f5">wheels::dm::flyweight::begin</a></div><div class="ttdeci">iterator begin()</div><div class="ttdef"><b>定义</b> <a href="#l00163">flyweight.hpp:163</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_aecc25a056ac2858e7ee8571e19c95245"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#aecc25a056ac2858e7ee8571e19c95245">wheels::dm::flyweight::set</a></div><div class="ttdeci">void set(const idType &amp;id, const T &amp;data)</div><div class="ttdef"><b>定义</b> <a href="#l00116">flyweight.hpp:116</a></div></div>
<div class="ttc" id="aclasswheels_1_1dm_1_1flyweight_html_afa4a8a1bb26896762077219548c45cb1"><div class="ttname"><a href="../../d5/da3/classwheels_1_1dm_1_1flyweight.html#afa4a8a1bb26896762077219548c45cb1">wheels::dm::flyweight::get</a></div><div class="ttdeci">variant get(const idType &amp;name)</div><div class="ttdoc">修改指定的内容</div><div class="ttdef"><b>定义</b> <a href="#l00103">flyweight.hpp:103</a></div></div>
<div class="ttc" id="aclasswheels_1_1variant_html"><div class="ttname"><a href="../../dd/d54/classwheels_1_1variant.html">wheels::variant</a></div><div class="ttdoc">实际暴露出来的接口类。这个类具有明确的类型，可以在其他容器中，比如vector中，使用</div><div class="ttdef"><b>定义</b> <a href="../../d9/d7a/variant_8hpp_source.html#l00082">variant.hpp:82</a></div></div>
<div class="ttc" id="aclasswheels_1_1variant_html_aec8c6372866cf7fd422a96e1164aa5c3"><div class="ttname"><a href="../../dd/d54/classwheels_1_1variant.html#aec8c6372866cf7fd422a96e1164aa5c3">wheels::variant::make</a></div><div class="ttdeci">static variant make(const dataType &amp;data)</div><div class="ttdoc">构建数据对象</div><div class="ttdef"><b>定义</b> <a href="../../d9/d7a/variant_8hpp_source.html#l00167">variant.hpp:167</a></div></div>
<div class="ttc" id="anamespaceprivate_____html"><div class="ttname"><a href="../../d4/da4/namespaceprivate____.html">private__</a></div><div class="ttdoc">代理模式</div><div class="ttdef"><b>定义</b> <a href="../../db/d94/mediator_8hpp_source.html#l00029">mediator.hpp:30</a></div></div>
<div class="ttc" id="anamespacewheels_html"><div class="ttname"><a href="../../df/d8d/namespacewheels.html">wheels</a></div><div class="ttdoc">堆栈信息读取和保存记录</div><div class="ttdef"><b>定义</b> <a href="../../d3/df7/ary__str_8hpp_source.html#l00006">ary_str.hpp:7</a></div></div>
<div class="ttc" id="avariant_8hpp_html"><div class="ttname"><a href="../../d9/d7a/variant_8hpp.html">variant.hpp</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.11.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
